package request

import (
	SpringWeb "github.com/go-spring/spring-web"
)

func BindPageInfo(webCtx SpringWeb.WebContext, i interface{}) error {
	return BindPageInfoExtra(webCtx, i, 1, 10)
}

func BindPageInfoExtra(webCtx SpringWeb.WebContext, i interface{}, p int, pSize int) error {
	err := webCtx.Bind(i)
	if err != nil {
		return err
	}

	pageInfo := i.(PageInfo)
	if pageInfo.PageSize == 0 {
		pageInfo.PageSize = pSize
	}

	if pageInfo.Page == 0 {
		pageInfo.Page = p
	}
	return nil
}
